package com.zkjl.protect_business.controller;

import com.zkjl.protect_business.common.ApiResponse;
import com.zkjl.protect_business.common.SystemLog;
import com.zkjl.protect_business.dto.BusinessTrainingDTO;
import com.zkjl.protect_business.dto.PageDTO;
import com.zkjl.protect_business.entity.BusinessTraining;
import com.zkjl.protect_business.service.BusinessTrainingService;
import com.zkjl.protect_business.utils.ResultUtil;
import com.zkjl.protect_business.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/businessTrainings")
@Api(tags = {"业务培训"})
public class BusinessTrainingController {

    @Autowired
    BusinessTrainingService businessTrainingService;

    @ApiOperation(value = "新增业务培训", notes = "新增业务培训", httpMethod = "POST")
    @PostMapping
    @SystemLog(description = "新增业务培训")
    public ApiResponse<BusinessTraining> save(@RequestBody @Validated BusinessTrainingDTO businessTrainingDTO) {

        BusinessTraining save = businessTrainingService.save(businessTrainingDTO);
        return ApiResponse.ofSuccess(save);

    }

    @ApiOperation(value = "业务培训列表", notes = "业务培训列表", httpMethod = "GET")
    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "search", value = "关键词" , paramType = "query"),
            @ApiImplicitParam(name = "type", value = "内容类型 视频 文件", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "下发开始时间", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "下发结束时间", paramType = "query"),
    })
    @SystemLog(description = "查询业务培训列表")
    public ApiResponse<PageVO<BusinessTraining>> page(PageDTO pageDTO, String search, String type, Long startTime, Long endTime) {

        PageImpl page = businessTrainingService.page(pageDTO, search,type, startTime, endTime);

        return ResultUtil.successPagesVO(page);

    }

    @ApiOperation(value = "删除业务培训", notes = "删除业务培训", httpMethod = "DELETE")
    @DeleteMapping(value = "{id}")
    @SystemLog(description = "删除业务培训")
    public ApiResponse del(@PathVariable String id) {

        Boolean del = businessTrainingService.del(id);
        return ApiResponse.ofSuccess(del);
    }

    @ApiOperation(value = "业务培训详情", notes = "业务培训详情", httpMethod = "GET")
    @GetMapping(value = "{id}")
    @SystemLog(description = "查看业务培训详情")
    public ApiResponse get(@PathVariable String id) {
        BusinessTraining businessTraining = businessTrainingService.get(id);
        return ApiResponse.ofSuccess(businessTraining);
    }

}
